package com.zy.configs;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 模板引擎配置
 */
@Configuration
public class VelocityConfig {
    @Bean
    public VelocityEngine velocityEngine(){
        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        velocityEngine.init();
        return velocityEngine;
    }

    /**
     * 模板上下文(map )
     * @return
     */
    @Bean
    public VelocityContext velocityContext(){
        VelocityContext context = new VelocityContext();
        return context;
    }
    @Bean
    public Template userLoginSuccessTemplate(@Autowired  VelocityEngine velocityEngine){
        Template template = velocityEngine.getTemplate("vms/userLoginSuccess.vm","utf-8");
        return template;
    }

}
